<template>
	<button @click="tomy" style="width: 100px;color: #fccd33;">保存</button>
	<!-- <button @click="aaa">1232</button> -->
	<view class="data">头像	<img :src="saveUserForm.imgUrl" width="50px" style="border-radius: 50%;border: 1px solid black;"></view>
	<hr>
	<view class="data">昵称 <input type="text" v-model="saveUserForm.name"></view>
	<hr>
	<view class="data">ID	<input type="text" v-model="saveUserForm.id" disabled></view>
	<hr>
	<view class="data">个性签名	<textarea id="a2" :rows="3" v-model="saveUserForm.content"/></view>
	<!-- <view class="data">个性签名	<textarea id="i2" :rows="3" v-model="saveUserForm.content"></view> -->
</template>

<script setup>
	import { onMounted,ref} from "vue";
	import {selectclient} from "@/api/mydata.js"
	import {saveclient} from "@/api/mydata.js"
	//定义对象用来保存用户弹窗表单数据
	const saveUserForm = ref({
	  id: '',
	  name: '',
	  imgUrl: '',
	  content: '',
	})
	// 从 localStorage 获取数据
	const clientId = localStorage.getItem('userid');
	// const saveUser = ref({
	// 	id=saveUserForm.id&
	// 	name=saveUserForm.name&
	// 	imgUrl=saveUserForm.imgUrl&
	// 	content=saveUserForm.content
	// })
	// const queryString = Object.keys(saveUserForm)
	//   .map(key => `${key}=${encodeURIComponent(saveUserForm[key])}`)
	//   .join('&');
	// const queryStringg = `id=${encodeURIComponent(1)}
	// &name=${encodeURIComponent(saveUserForm.name)}
	// &imgUrl=${encodeURIComponent(saveUserForm.imgUrl)}
	// &content=${encodeURIComponent('管理员111')}`;

	//一进入页面就加载
	onMounted(()=>{
	  select();
	})
	const select =async () => {
		let res = await selectclient(1);
		console.log(res);
		console.log(res.data[0]);
		saveUserForm.value = res.data[clientId-1];
		console.log(saveUserForm.value);
	}
	const aaa =()=>{
		console.log(saveUserForm.value);
		// console.log(queryString);
		// console.log(queryString.value);
		// console.log(queryString.valueOf(saveUserForm));
		// console.log(queryStringg);
		console.log(clientId);
	}
	const tomy=async () => {
		let res = await saveclient(saveUserForm.value);
		console.log('9998');
		console.log(res);
		uni.showToast({
			title: '保存成功'
		})
		uni.switchTab({
			url: "/pages/my/my"
		})
	}
</script>

<style>
	.data {
		margin-top: 50px;
		margin-bottom: 50px;
	}
	#i1 {
		border-bottom: 1px solid black;
		width: 200px; 
		height: 40px;
		margin: 0 auto;
	}
	#a2 {
		background-color: #fff;
		/* margin: 0 auto; */
		height: 150px; /* 设置输入框的高度 */
		/* line-height: 50px; /* 设置行高与高度相同，使文本垂直居中 */ 
		padding: 0; /* 移除默认的内边距 */
		box-sizing: border-box; /* 确保内边距和边框不会增加元素的总宽度和高度 */
		width: 100%;
	}
</style>
